<?php

/**
 * <pre>
 * if($handler =  Event::load($action))
 * {
 * 	Event::emit($handlers, $action,	$subject, $params);
 * }
 * </pre>
 */
class Hook
{

	static protected $_hooks = null;

	/**
	 * @param string $action
	 * @return array/FALSE
	 */
	static public function load($action)
	{
		if (null == self::$_hooks)
		{
			self::$_hooks = Agilet::loadConfig('hook');
		}

		if (isset(self::$_hooks[$action]))
		{
			return self::$_hooks[$action];
		}
		return FALSE;
	}

	static public function emit($hooks, $action, $param_arr = null)
	{

		if (!$hooks)
		{
			return;
		}

		$param_arr = (array)$param_arr;

		foreach ($hooks as $class)
		{
			try
			{

				call_user_func_array(array(
					$class,
					$action
				), $param_arr);
			}
			catch(Exception $exception)
			{
				Agilet::__exceptionHandler($exception);
			}
		}
	}

}
